@extends('manage.layout')

@section('content')
    <section class="content-header">
        <h1>
            线索跟进记录
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="#">Clue</a></li>
            <li class="active">Follow List</li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title">内容</h3>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body">
                        <table class="table table-bordered table-hover">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>权重</th>
                                <th>创建时间</th>
                                <th>线索名</th>
                                <th>公司名</th>
                                <th>拜访时间</th>
                                <th>拜访人员</th>
                                <th>陪同人</th>
                                <th>拜访形式</th>
                                <th>拜访结果</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($follow as $f)
                                <tr>
                                    <td>{{ $f['id'] }}</td>
                                    <td>{{ $f['rank'] }}</td>
                                    <td>{{ $f['create_time'] }}</td>
                                    <td>{{ App\Model\Clue::find($f['clue_id'])['name'] }}</td>
                                    <td>{{ App\Model\Clue::find($f['clue_id'])['company'] }}</td>
                                    <td>{{ $f['time'] }}</td>
                                    <td>{{ $f['personnel'] }}</td>
                                    <td>
                                        @if(empty($f['accompany']))无
                                        @else{{ $f['accompany'] }}
                                        @endif
                                    </td>
                                    <td>
                                        @if($f['form'] ==0 )上门
                                        @elseif($f['form'] ==1)来人
                                        @elseif($f['form'] ==2)电话
                                        @elseif($f['form'] ==3)网络
                                        @endif
                                    </td>
                                    <td>{{ $f['result'] }}</td>
                                    <td>
                                        {{--<a class="btn btn-danger btn-xs" href="javascript:delFollow({{ $f['id'] }})">删除<a>--}}
                                        @if($f['status'] == 1)
                                            <a class="btn btn-danger btn-xs" href="javascript:followStatus('{{ $f['id'] }}',0)">禁用<a>
                                        @elseif($f['status'] == 0)
                                            <a class="btn btn-success btn-xs" href="javascript:followStatus('{{ $f['id'] }}',1)">启用<a>
                                        @endif
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </div>
                    <!-- /.box-body -->
                </div>
            </div>
            <!-- /.col -->
        </div>
        <!-- /.row -->
    </section>
@stop
@section('script')
    <script>
        //删除
//        function delFollow(id) {
//            layer.confirm('删除后不可恢复，是否继续?', {
//                btn:['确定','取消']
//            },function() {
//                $.ajax({
//                    url: 'delFollow/'+id,
//                    type: "GET",
//                    data: id,
//                    dataType: "json",
//                    success: function(res) {
//                        console.log(res);
//                        if(res.code == 100) {
//                            window.location.href = "index";
//                            layer.msg(res.msg)
//                        }
//                        else {
//                            layer.msg(res.msg)
//                        }
//                    }
//                });
//            },function() {
//
//            });
//        }

        //禁用,启用
        function followStatus(id,status) {
            $.ajax({
                url: '/clue/followStatus',
                type: "GET",
                data: {id:id,status:status},
                dataType: "json",
                success: function(res) {
                    console.log(res);
                    if(res.code == 100) {
                        window.location.href=window.location.href;
                        layer.msg(res.msg, {time:1500, icon:6})
                    }
                    else {
                        layer.msg(res.msg, {time:1500, icon:5});

                    }
                }
            });
        }
    </script>
@stop